<?php
require "Db\DbHelper.php";
require "Tools\WebResult.php";

use Tools\WebResult;
use Db\DbHelper;

$user_name = $_REQUEST["user_name"];
$user_pass = $_REQUEST["user_pass"];

$db = DBHelper::createPDO();
$stmt = $db->prepare('select * from user where name = ? and pwd = ?');
$stmt->bindValue(1, $user_name);
$stmt->bindValue(2, $user_pass);

$stmt->execute();

$row = $stmt->fetch();

if (empty($row)) {
    WebResult::JsonFail("Invalid login，please login again.");
}

$_SESSION['user'] = $row;

WebResult::JsonSuccess("login_successful！");
